/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.nii.qlks.BusinessLogicLayer;

import edu.nii.qlks.DataAccessLayer.MSSQLConnectUnit;
import edu.nii.qlks.DataTransferObject.BCMatDoInfo;
import edu.nii.qlks.DataTransferObject.CTBCMatDoInfo;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;

/**
 *
 * @author KUUT
 */
public class CTBCMatDo {
    MSSQLConnectUnit _connect;
    ResultSet  _result;
 
    
    public ArrayList LayDS(String Condition, String OderBy) throws Exception{
        ArrayList vt = new ArrayList();
        
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        _result = _connect.Select("CTBCMATDO", Condition, OderBy);
        
        while (_result.next()){
            ArrayList vt_row = new ArrayList();
            vt_row.add(_result.getString(1));
            vt_row.add(_result.getString(2));
            vt_row.add(_result.getString(3));
            vt_row.add(_result.getString(4));
            vt_row.add(_result.getString(5));
            vt.add(vt_row);
        }
        _connect.Close();
        return vt;
    }
    
    public ArrayList LayDS(String Condition) throws Exception{
         return LayDS(Condition, null);
    }
    
    public ArrayList LayDS() throws Exception{
        return LayDS(null);
    }
    
    public void Insert(CTBCMatDoInfo bangkedichvu_info) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        HashMap<String, Object> map = new HashMap<>();
        map.put("MaCTBaoCao", bangkedichvu_info.getMaCTBaoCao());
        map.put("MaBaoCao", bangkedichvu_info.getMaBaoCao());
        map.put("MaPhong", bangkedichvu_info.getMaPhong());
        map.put("SoNgayThue", bangkedichvu_info.getSoNgayThue());
        map.put("TyLe", bangkedichvu_info.getTyLe());
        _connect.Insert("CTBCMATDO", map);
    }
     
    public void Inserts(HashSet<CTBCMatDoInfo> bangkedichvu_info) throws Exception{
        for (CTBCMatDoInfo Info : bangkedichvu_info) {
            this.Insert(Info);
        }
    }
    
    public void Update(CTBCMatDoInfo bangkedichvu_info) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        HashMap<String, Object> map = new HashMap<>();
        map.put("MaBaoCao", bangkedichvu_info.getMaBaoCao());
        map.put("MaPhong", bangkedichvu_info.getMaPhong());
        map.put("SoNgayThue", bangkedichvu_info.getSoNgayThue());
        map.put("TyLe", bangkedichvu_info.getTyLe());
        
        _connect.Update("CTBCMATDO", map, "MaCTBaoBao = '" + bangkedichvu_info.getMaCTBaoCao() + "'");
    }
    
    public void Updates(HashSet<CTBCMatDoInfo> bangkedichvu_info) throws Exception{
        for (CTBCMatDoInfo Info : bangkedichvu_info){
            this.Update(Info);
        }
    }
    
    public void Delete(CTBCMatDoInfo bangkedichvu_info) throws Exception{
        _connect = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.getConnection();
        _connect.Delete("CTBCMATDO", "MaCTBaoCao = '" + bangkedichvu_info.getMaCTBaoCao() + "'");
    }
    
    public void Deletes(HashSet<CTBCMatDoInfo> bangkedichvu_info) throws Exception{
         for (CTBCMatDoInfo Info : bangkedichvu_info){
            this.Delete(Info);
        }
    }
    
    public String TaoMaTuDong(String maGoc, int batDau){
        String ma = edu.nii.qlks.BusinessLogicLayer.BusinessLogicAbstract.TaoMaTuDong(maGoc, batDau);
        return ma;
    }
}
